package org.dromara.utils.utils;

import org.dromara.Nyt7Claim.domain.vo.Nyt7ClaimVo;

import java.util.*;

public class ClaimUtil {

    public static List<Nyt7ClaimVo> filter(List<Nyt7ClaimVo> nyt7ClaimVos, String X) {
        List<Nyt7ClaimVo> removeList = new ArrayList<>();
        Map<String,Nyt7ClaimVo> map = new HashMap<>();
        if(Objects.equals(X, "company")){
            //同公司名称的保单合并
            for (Nyt7ClaimVo nyt7ClaimVo : nyt7ClaimVos){

                String postName = nyt7ClaimVo.getCompanyName();
                if(map.containsKey(postName)){
                    Nyt7ClaimVo nyt7PolicyInsurance1 = map.get(postName);
                    nyt7PolicyInsurance1.addFields(nyt7ClaimVo);
                    removeList.add(nyt7ClaimVo);
                }else{
                    map.put(postName,nyt7ClaimVo);
                }
            }
            nyt7ClaimVos.removeAll(removeList);
        } else if (Objects.equals(X, "region")) {
            for (Nyt7ClaimVo nyt7ClaimVo : nyt7ClaimVos){

                String region = nyt7ClaimVo.getRegion();
                if(map.containsKey(region)){
                    Nyt7ClaimVo nyt7PolicyInsurance1 = map.get(region);
                    nyt7PolicyInsurance1.addFields(nyt7ClaimVo);
                    removeList.add(nyt7ClaimVo);
                }else{
                    map.put(region,nyt7ClaimVo);
                }
            }
            nyt7ClaimVos.removeAll(removeList);
        }

        return nyt7ClaimVos;
    }
}
